local wanrong = fk.CreateSkill {

  name = "joyex__wanrong",

  tags = {  },

}



wanrong:addEffect("active", {
  name = "joyex__wanrong",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(wanrong.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  interaction = function(self,player)
    return UI.ComboBox {choices = {"joyex__wanrong_use" , "joyex__wanrong_throw"}}
  end,
  card_filter = function(self, player, to_select, selected)
    if #selected > 0 or not self.interaction.data or Fk:getCardById(to_select).suit ~= Card.Diamond then return false end
    if self.interaction.data == "joyex__wanrong_use" then
      local card = Fk:cloneCard("indulgence")
      card:addSubcard(to_select)
      return player:canUse(card) and not player:prohibitUse(card)
    else
      return not player:prohibitDiscard(Fk:getCardById(to_select))
    end
  end,
  target_filter = function(self, player, to_select, selected)
    if #cards ~= 1 or #selected > 0 or not self.interaction.data then return false end
    local target = Fk:currentRoom():getPlayerById(to_select)
    if self.interaction.data == "joyex__wanrong_use" then
      local card = Fk:cloneCard("indulgence")
      card:addSubcard(cards[1])
      return to_select ~= player.id and not player:isProhibited(target, card)
    else
      return target:hasDelayedTrick("indulgence")
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if self.interaction.data == "joyex__wanrong_use" then
      room:useVirtualCard("indulgence", effect.cards, player, target, wanrong.name)
    else
      room:throwCard(effect.cards, wanrong.name, player, player)
      for _, id in ipairs(target.player_cards[Player.Judge]) do
        local card = target:getVirualEquip(id)
        if not card then card = Fk:getCardById(id) end
        if card.name == "indulgence" then
          room:throwCard({id}, wanrong.name, target, player)
        end
      end
    end
  end,
})

return wanrong